package com.lhnstart.learn.bases.do_question_;

/**
 * 01
 *
 * @author lhn
 * @date 2023/06/19 13:50
 * @since 1.0.0
 **/
public class Homework01 {

    public static void main(String[] args) {
        Person person1 = new Person("小明", 23, "程序员");
        Person person2 = new Person("小李", 25, "产品经理");
        Person person3 = new Person("小刘", 26, "项目经理");
        Person[] persons = new Person[3];
        persons[0] = person1;
        persons[1] = person2;
        persons[2] = person3;
        for (Person person : persons) {
            System.out.println(person);
        }
        for (int i = 0; i < persons.length-1; i++) {
            for (int i1 = 0; i1 < persons.length - i - 1; i1++) {
                if (persons[i1].getAge() < persons[i1 + 1].getAge()) {
                    Person tamp = persons[i1];
                    persons[i1] = persons[i1 + 1];
                    persons[i1 + 1] = tamp;
                }
            }
        }
        for (Person person : persons) {
            System.out.println(person);
        }


    }

}

class Person {
    String name;

    int age;

    String job;

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Person{");
        sb.append("name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append(", job='").append(job).append('\'');
        sb.append('}');
        return sb.toString();
    }
}